import 'dart:ffi';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';

class dataUtil {

  static Future<Void> setValue(String key, dynamic value) {
    SharedPreferences prefs = SpUtil.preferences;
    if (value is String) {
      prefs.setString(key, value);
    }
  }

  static dynamic getValue(String key){
    SharedPreferences prefs = SpUtil.preferences;
    return prefs.get(key);
  }

  static dynamic removeValue(String key){
    SharedPreferences prefs = SpUtil.preferences;
    return prefs.remove(key);
  }

  static bool removeAll() {
    dataUtil.removeValue(dataUtil.nickNameKey);
    dataUtil.removeValue(dataUtil.assistantAvatarKey);
    dataUtil.removeValue(dataUtil.assistantPhoneKey);
    dataUtil.removeValue(dataUtil.tokenKey);
    dataUtil.removeValue(dataUtil.assistantIdKey);
    dataUtil.removeValue(dataUtil.upLoadTokenKey);
    return true;
  }
  
  //用来管理所有的存储 key
  static String nickNameKey = "nickNameKey";
  static String assistantPhoneKey = "assistantPhoneKey";
  static String assistantAvatarKey = "assistantAvatarKey";
  static String assistantIdKey = "assistantIdKey";
  static String tokenKey = "tokenKey";
  static String upLoadTokenKey = "upLoadTokenKey";
  static String evaluationCountKey = "evaluationCountKey";
  static String markKey = "markKey";
  //全局的 context
  static BuildContext context;
}

class SpUtil{
  static SharedPreferences preferences;
  static Future<bool> getInstance() async{
     preferences = await SharedPreferences.getInstance();
     return true;
  }
}
